package com.ashapo.example;

public class Example010This {

    public static void main(String[] args) {
        Student s1 = new Student(111, "ankit", 5000f);
        Student s2 = new Student(112, "sumit", 6000f);
        s1.display();
        s2.display();

        A a = new A(10);

        Student s12 = new Student(111, "ankit", 5000f);
        Student s22 = new Student(112, "sumit", "java", 6000f);
        s12.display();
        s22.display();

        S2 s122 = new S2();
        s122.p();
    }
}

class Student {
    private int rollno;
    private String name;
    private float fee;

    private String course;

    /**
     * 测试使用this关键字区分变量名
     * @param rollno 角色
     * @param name 名称
     * @param fee 费用
     */
    Student(int rollno, String name, float fee) {
        this.rollno = rollno;
        this.name = name;
        this.fee = fee;
    }

    Student(int rollno, String name, String course, float fee) {
        this(rollno, name, fee);  //调用指定构造器，必须放在第一句执行，否则会报错
        this.course = course;
    }

    void display() {
        System.out.println(rollno + " " + name + " " + fee);
        System.out.println(rollno + " " + name + " " + course + " " + fee);
    }
}

class A {
    A() {
        System.out.println("hello a");
    }

    A(int x) {
        this();  //调用无参构造
        System.out.println(x);
    }
}

class S2 {
    void m(S2 obj) {
        System.out.println(obj.toString());
        System.out.println("method is invoked");
    }

    void p() {
        m(this);  //this：作为参数传递给方法
    }
}
